//
//  FriendsCell.m
//  PHMall
//
//  Created by admin on 2018/1/19.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "FriendsCell.h"

@implementation FriendsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
+ (instancetype)theShareCellWithTableView:(UITableView *)tableView{
    
    static NSString *ID = @"SetCell";
    FriendsCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[FriendsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.headImage=[[UIImageView alloc]init];
        self.headImage.image=[UIImage imageNamed:@"头像"];
        ViewBorderRadius(self.headImage, 3, 0.5, [UIColor groupTableViewBackgroundColor]);
        [self.contentView addSubview:self.headImage];
        //
        self.name=[[UILabel alloc]init];
        self.name.text=@"收件人阿萨德";
        self.name.font=[UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.name];
        
        self.select=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.select setImage:[UIImage imageNamed:[NSString stringWithFormat:@"未选中"]] forState:UIControlStateNormal];
        [self.select setImage:[UIImage imageNamed:[NSString stringWithFormat:@"选中"]] forState:UIControlStateSelected];
        [self.select addTarget:self action:@selector(selectAction) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.select];
        
        self.line=[[UIView alloc]init];
        [self.contentView addSubview:self.line];
        self.line.backgroundColor=[UIColor colorWithHexString:@"#ECEBEC"];
      
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.contentView.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.select mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).with.offset(5);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];
    
    [self.headImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.select.mas_right).offset(10);
        make.centerY.offset(0);
        make.width.height.offset(35);
    }];
    
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImage.mas_right).offset(10);
        make.centerY.offset(0);
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.height.offset(1);
    }];
}
-(void)selectAction{
    if (self.delegate && [self.delegate respondsToSelector:@selector(selectedAction:)]) {
        [self.delegate selectedAction:self];
    }
}
-(void)setModel:(FriendsModel *)model{
    _model=model;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@union/%@",IMGURL,model.img]] placeholderImage:[UIImage imageNamed:@"图片空白页"]];
    self.name.text=model.member_id;
    self.select.selected=model.select;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
